<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_出库拣货任务</title>
<script type="text/javascript">
  
   //完成拣货任务
   function completeTask(taskId){
	   $("#btn_complete").attr("disabled", true);
       $.ajax({
			type:'post',
			url:'${ctx}/v2/outstoragePickTask/ajaxCompletePickTask',
			data:{
				taskId:taskId
			},
			dataType:'json',
			success:function(data) {
			    if(data==true){
			      window.alert("完成拣货！！请按“确定”继续。"); 
		          location.href='${ctx}/v2/outstoragePickTask/queryPickTaskList';
			    }else{
			      $("#btn_complete").attr("disabled", false);
			      alert("网络繁忙，请稍后重试...");
			    }
			},
			error:function() {
				$("#btn_complete").attr("disabled", false);
				alert("网络繁忙，请稍后重试...");
			}
	   });
       
   }
   //---------------打印拣货单----------------
	function AjaxPagePrinter(){
		printName = $("#pickPickPrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/outstoragePickTask/ajaxPrintPickInfo',
			data : {
				billCode : billCode
			},
			dataType : 'json',
			success : function(data){
				if(data.status == "1"){
					printPickInfo(data.itemList,printName);
					closeBg();
				}else{
					alert("打印加载错误！");
				}
			}
		});
	}
	function printPickInfo(taskItem,printName){
		var taskCode = taskItem[0].billCode;
		var str = '';
		var num = 0;
		LODOP.PRINT_INIT(taskCode);
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '7' align = 'center'><h3>拣货单(任务编号："+taskCode+")</h3></td></tr>";
		str +="<tbody align = 'center'><tr><td colspan= '2'>仓库</td><td colspan= '2'>"+taskItem[0].warehouseCode+"</td></tr>";
		str += "<tr style='font-size:10pt'><td width='7%'>序号</td><td width='10%'>商家</td><td width='18%'>库位</td><td width='18%'>箱位</td><td width='20%'>sku</td><td width='20%'>商品名</td><td width='7%'>数量</td></tr>";
		for(var i =0;i<taskItem.length;i++){
			str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].boxCode+"</td><td>"+taskItem[i].sku+"</td><td>"+taskItem[i].skuName+"</td><td>"+taskItem[i].num+"</td></tr>";
			num += taskItem[i].num;
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '6'><h4>拣货单(任务编号："+taskCode+")</h4></td><td>"+num+"</td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A5") ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}
</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">任务信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
    <table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead><tr>
		        <th>商家</th>
		        <th>出库类型</th>
		        <th>仓库</th>
			    <th>任务编号</th>
			    <th>sku数量</th>
			    <th>商品数量</th>
			    <th>任务状态</th>
			    <th>操作</th>
			</tr>
	   </thead>
	   <tr>
	      <td>${task.customer.customerName}</td>
	      <td>
			  <c:if test="${task.bill.billType eq 'allot' }"><font color=red>调拨出库</font></c:if> 
			  <c:if test="${task.bill.billType eq 'sale' }"><font color=blue>销售出库</font></c:if>
			  <c:if test="${task.bill.billType eq 'return' }"><font color=green>返仓出库</font></c:if>
		  </td>
	      <td>${task.warehouse.groupName}</td>
	      <td>${task.taskCode}</td>
	      <td>${task.bill.skuNum}</td>
	      <td>${task.bill.goodsNum}</td>
	      <td>
		     <c:if test="${task.status eq 'undo'}"><font color=blue>创建任务</font></c:if>
		     <c:if test="${task.status eq 'token'}"><font color=blue>领取任务</font></c:if>
		     <c:if test="${task.status eq 'doing'}"><font color=blue>拣货中</font></c:if>
		     <c:if test="${task.status eq 'finish'}"><font color=blue>拣货完成</font></c:if>
	     </td>
	     <td>
           <a href="${ctx}/v2/outstoragePickTask/exportExcel/${task.id}"  role="button" class="btn btn-info" >导出拣货单</a>
           <a href="#printPickInfo"  data-toggle="modal" role="button" class="btn btn-primary" onclick="changeStatus('${task.billCode}')">打印</a>
           <c:if test="${task.status eq 'token' or task.status eq 'doing'}">
               <input type="button" class="btn btn-primary" id="btn_complete" value="完成拣货" onclick="completeTask('${task.id}');">
           </c:if>
	     </td>
	   </tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">拣货明细</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>出库单编号</th>
			    <th>仓库</th>
			    <th>SKU编号</th>
			    <th>库位</th>
			    <th>箱号</th>
			    <th>数量</th>
			</tr></thead>
		<tbody>
		<c:forEach items="${itemList}" var="o" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${o.billCode}</td>
			   <td>${o.warehouseCode}</td>
			    <td>${o.sku}</td>
			     <td>${o.stockCode}</td>
			      <td>${o.boxCode}</td>
			       <td>${o.num}</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printPickInfo">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印拣货单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;">
						<div class="control-group">
							<div class="controls">
								  选择打印机:
								<select id="pickPickPrint" name="packFormPrinter" style="width: 300px">
		
								</select>
							</div>
						</div>
					</div>
					
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="AjaxPagePrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		  	</div>
		  </div>
		</div>
	</section>
	<script type="text/javascript">
		var billCode = '';
		function changeStatus(code){
			billCode = code;
			packFormPrinter("pickPickPrint");
		}
	
	</script>
</body>
</html>
